package com.smart.campus.web.controller.school;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.PsychologicalTestItem;
import com.smart.campus.school.service.IPsychologicalTestItemService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 心理测试题Controller
 * 
 * @author Zhihe.Li
 * @date 2020-05-27
 */
@Controller
@RequestMapping("/school/psychologicaItem")
public class PsychologicalTestItemController extends BaseController
{
    private String prefix = "school/psychologicaItem";

    @Autowired
    private IPsychologicalTestItemService psychologicalTestItemService;

    @RequiresPermissions("school:psychologicaItem:view")
    @GetMapping()
    public String psychologicaItem()
    {
        return prefix + "/psychologicaItem";
    }

    /**
     * 查询心理测试题列表
     */
    @RequiresPermissions("school:psychologicaItem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PsychologicalTestItem psychologicalTestItem)
    {
        startPage();
        List<PsychologicalTestItem> list = psychologicalTestItemService.selectPsychologicalTestItemList(psychologicalTestItem);
        return getDataTable(list);
    }

    /**
     * 导出心理测试题列表
     */
    @RequiresPermissions("school:psychologicaItem:export")
    @Log(title = "心理测试题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PsychologicalTestItem psychologicalTestItem)
    {
        List<PsychologicalTestItem> list = psychologicalTestItemService.selectPsychologicalTestItemList(psychologicalTestItem);
        ExcelUtil<PsychologicalTestItem> util = new ExcelUtil<PsychologicalTestItem>(PsychologicalTestItem.class);
        return util.exportExcel(list, "psychologicaItem");
    }

    /**
     * 新增心理测试题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存心理测试题
     */
    @RequiresPermissions("school:psychologicaItem:add")
    @Log(title = "心理测试题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PsychologicalTestItem psychologicalTestItem)
    {
        return toAjax(psychologicalTestItemService.insertPsychologicalTestItem(psychologicalTestItem));
    }

    /**
     * 修改心理测试题
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PsychologicalTestItem psychologicalTestItem = psychologicalTestItemService.selectPsychologicalTestItemById(id);
        mmap.put("psychologicalTestItem", psychologicalTestItem);
        return prefix + "/edit";
    }

    /**
     * 修改保存心理测试题
     */
    @RequiresPermissions("school:psychologicaItem:edit")
    @Log(title = "心理测试题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PsychologicalTestItem psychologicalTestItem)
    {
        return toAjax(psychologicalTestItemService.updatePsychologicalTestItem(psychologicalTestItem));
    }

    /**
     * 删除心理测试题
     */
    @RequiresPermissions("school:psychologicaItem:remove")
    @Log(title = "心理测试题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(psychologicalTestItemService.deletePsychologicalTestItemByIds(ids));
    }
}
